# $Id: PKGBUILD 82927 2013-01-25 21:40:08Z spupykin $
# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Maintainer: Moritz Rudert <helios@cyb0rg.org>

pkgname=pymsnt
pkgver=0.11.3
pkgrel=8
pkgdesc="jabber msn transport"
arch=(any)
url="http://delx.net.au/projects/pymsnt/"
license=('GPL')
backup=(etc/ejabberd/pymsn.xml)
depends=('python2' 'twisted' 'python2-pyopenssl')
source=(http://delx.net.au/projects/pymsnt/tarballs/pymsnt-$pkgver.tar.gz
	pymsn.rc
	pymsnt.service
	config.xml
	pymsnt-version.patch)
md5sums=('e74049fb1bfae59846b1be3d4ef80299'
         '40627f2cb05618771728d29d7c3a6999'
         'ecf20ab8360211436f7c9d149b6a3420'
         '4c07c88403515f1da61974b57acf8db7'
         '50c03d89ca1f682ebffcfacb70d1ba00')

build() {
  cd $srcdir
  patch -p0 < $srcdir/pymsnt-version.patch

  # python2 fix
  for file in $(find . -name '*.py' -print); do
    sed -i 's_^#!.*/usr/bin/python_#!/usr/bin/python2_' $file
    sed -i 's_^#!.*/usr/bin/env.*python_#!/usr/bin/env python2_' $file
  done

  install -d -m0755 $pkgdir/usr/lib
  cp -r ${pkgname}-$pkgver $pkgdir/usr/lib
  mv $pkgdir/usr/lib/${pkgname}-$pkgver $pkgdir/usr/lib/$pkgname
  install -d -m0755 $pkgdir/var/spool/pymsnt
  install -D -m0644 ./config.xml $pkgdir/etc/ejabberd/pymsn.xml
  mv $pkgdir/usr/lib/$pkgname/config-example.xml $pkgdir/etc/ejabberd/pymsn_example.xml
  ln -s ../../../etc/ejabberd/pymsn.xml $pkgdir/usr/lib/$pkgname/config.xml
  install -D -m0755 pymsn.rc $pkgdir/etc/rc.d/pymsnt

  install -Dm0644 $srcdir/$pkgname.service $pkgdir/usr/lib/systemd/system/$pkgname.service
}
